<template>
  <div>
    <el-form-item label="品牌类型 ：">
      <el-col :span="20">
        <el-input type="text" :value="thisdata.str" :maxlength="100" placeholder="选择品牌类型" @focus="dialogFormVisible = true">
        </el-input>
      </el-col>
    </el-form-item>
    <el-dialog title="选择类型" :visible.sync="dialogFormVisible">
      <el-row>
        <el-col :span="6" class="checkboxList" v-for="item in options" :key="item">
          <el-checkbox :label="item.value" v-model="newdata">{{item.label}}</el-checkbox>
        </el-col>
      </el-row>
      <div slot="footer" class="dialog-footer">
        <el-button @click="check_button(false)">取 消</el-button>
        <el-button type="primary" @click="check_button(true)">确 定</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
  export default {
    props: {
      value: {
        type: Array
      },
      options: {
        type: Array,
        default () {
          return {
            label: '',
            value: ''
          }
        }
      },
      disabled: {}
    },
    mounted () {
      this.newdata = this.value
      this.thisdata.str = this.getStr()
    },
    data () {
      return {
        dialogFormVisible: false,
        newdata: [],
        thisdata: {
          str: '',
          olddata: []
        }
      }
    },
    methods: {
      check_button (type) {
        if (!type) this.newdata = this.value
        this.dialogFormVisible = false
        this.thisdata.str = this.getStr()
        this.$emit('input', this.newdata).$emit('change', this.newdata)
        this.$emit('update:label', this.thisdata.str)
      },
      getStr () {
        let str = ''
        let list = this.options
        let data = this.newdata
        if (data) {
          data.map(i => {
            list.map(l => {
              if (l.value === i) {
                str += l.label + ';'
              }
            })
          })
        }
        return str
      }
    }
  }
</script>

<style lang="scss">
  .checkboxList {
    margin: 5px 0;
  }
</style>
